// components/tabbar/index.js
const App = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    activeIdx: {
      type: Number,
      value: 0
    },
    auth: {
      type: Number,
      value: 0,
      observer: 'onAuthChanged'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    BOTTOM_DISTANCE:App.globalData.BOTTOM_DISTANCE,
    tabbar_items: App.globalData.tabbar_items,
    tabbar_config: App.globalData.tabbar_config,
    _auth: 1
  },

  lifetimes: {
    attached: function () {
      this.setData({
        tabbarHeight:App.globalData.tabbarHeight,
        BOTTOM_DISTANCE:App.globalData.BOTTOM_DISTANCE,
        tabbar_items: App.globalData.tabbar_items,
        tabbar_config: App.globalData.tabbar_config,
        _auth: 0
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    handleItemTap(e) {
      const {
        idx,
        path
      } = e.currentTarget.dataset
      // console.log( path)
      //  ?? 这个判断是
      // if (idx === this.data.activeIdx) {
      //   this.trigger('refresh')
      //   return
      // }

      wx.switchTab({
        url: `/${path}`,
      })
    },
    onAuthChanged(newVal) {
  
      this.setData({
        _auth: newVal
      });
    },
    trigger(eventName, value = {}, info) {
      if (!eventName) {
        throw new TypeError('没有自定义事件名')
      }
      this.triggerEvent(eventName, value);
      // console.log(`发送 ${eventName} 事件,携带的值为 ${typeof value === 'object' ? JSON.stringify(value) : value} ${info ? '   ---   ' + info : ''}`)
    }
  },
  ready() {},
  pageLifetimes: {
    show: function() {
      this.setData({
        _auth: wx.getStorageSync('__com-tabbar-auth') || 0
      })
    }
  }
})
